package com.yunze.quartz.task.yunze.Automation;

import com.alibaba.fastjson.JSON;
import com.yunze.common.core.domain.entity.SysDictData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 定时任务 自动化 NB 超用量 300 MB 邮件通知
 *
 * @author root
 */
@Component("emailNBExceed")
public class EmailNBExceed {


    @Resource
    private RabbitTemplate rabbitTemplate;

    public void NBExceed(Integer cc_count) {
        //1.创建路由 绑定 生产队列 发送消息
        //导卡 路由队列
        String polling_queueName = "admin_NBExceed_queue";
        String polling_routingKey = "admin.NBExceed.queue";
        String polling_exchangeName = "admin_exchange";//路由
        try {
            Map<String, Object> start_type = new HashMap<>();
            start_type.put("cc_count",cc_count);
            rabbitTemplate.convertAndSend(polling_exchangeName, polling_routingKey, JSON.toJSONString(start_type), message -> {
                // 设置消息过期时间 30 分钟 过期
                message.getMessageProperties().setExpiration("" + (30 * 1000 * 60));
                return message;
            });
        } catch (Exception e) {
            System.out.println("NB 超用量 300 MB 邮件通知 失败 " + e.getMessage());
        }
    }




    public void clearEecordNBExceed() {
        //1.创建路由 绑定 生产队列 发送消息
        //导卡 路由队列
        String polling_queueName = "admin_clearEecordNBExceed_queue";
        String polling_routingKey = "admin.clearEecordNBExceed.queue";
        String polling_exchangeName = "admin_exchange";//路由
        try {
            Map<String, Object> start_type = new HashMap<>();
            rabbitTemplate.convertAndSend(polling_exchangeName, polling_routingKey, JSON.toJSONString(start_type), message -> {
                // 设置消息过期时间 30 分钟 过期
                message.getMessageProperties().setExpiration("" + (30 * 1000 * 60));
                return message;
            });
        } catch (Exception e) {
            System.out.println("清空 yz_automation_cc_monthly_record 指令发送 记录 失败 " + e.getMessage());
        }
    }


}
